package com.fw.controller;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.fw.entity.MyException;
import com.fw.entity.Result;
import com.fw.entity.User;
import com.fw.service.IUserService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
public class TestController {
    @Resource
    IUserService userService;
    @RequestMapping("/test")
    public String test(@RequestParam int num) throws MyException {
        if(num == 1)
            throw new MyException("123","123");
        return "test";
    }
    @RequestMapping("/arrange/listCompl")
    public Result list(@RequestBody Map<String, Object> map){
        System.out.println(map.get("lis"));
        System.out.println(map.get("lis_number"));
        return new Result(null, "获取成功", "000000");
    }
    @RequestMapping("/addList")
    public Result addList(String param){
        //转化数组，判断格式
        System.out.println(param);
        JSONArray numarray = JSONUtil.parseArray(param);
        for (int i = 0; i < numarray.size(); i++){
            User user = new User();
            System.out.println(user);
        }
        return new Result(null, "message", "000000");
    }
    @RequestMapping("/listUser")
    public Result listUser(){

        return new Result(userService.list(), "message", "000000");
    }
}
